package com.bkgy.controller.repTcmThickWidth.controller;

import com.alibaba.excel.util.StringUtils;
import com.bkgy.commom.model.BaseRangeObj;
import com.bkgy.controller.repTcmThickWidth.entity.pdo.ClientSteelGradeThickWidthRes;
import com.bkgy.controller.repTcmThickWidth.entity.pdo.SteelGradeThickWidthRes;
import com.bkgy.controller.repTcmThickWidth.service.IRepTcmThickWidthService;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.DateUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Tag(name = "钢种宽度厚度分析")
@Controller
@RequiredArgsConstructor
@RequestMapping("/repTcmThickWidth")
public class RepTcmThickWidthController {
    private final IRepTcmThickWidthService service;

    @ResponseBody
    @Operation(summary = "酸轧钢种宽度厚度分析报表", description = "酸轧钢种宽度厚度分析报表")
    @PostMapping("/steelRep")
    public ResultData<SteelGradeThickWidthRes> steelRep(@RequestBody BaseRangeObj obj) {
        String beginDate = obj.getBeginDate();
        String endDate = obj.getEndDate();
        if (StringUtils.isEmpty(beginDate)) {
            //不传开始时间，查询昨日数据
            beginDate = DateUtil.getDateToString(DateUtil.getLastDayZero(new Date()), "yyyyMMdd");
            endDate = DateUtil.getDateToString(DateUtil.getCurrentZero(new Date()), "yyyyMMdd");
        } else if ((beginDate.endsWith("00:00:00") && endDate.endsWith("00:00:00"))) {
            //区分整日查询和精确查询
            beginDate = DateUtil.tranceDateFormat(obj.getBeginDate(), "yyyy-MM-dd HH:mm:ss", "yyyyMMdd");
            endDate = DateUtil.tranceDateFormat(obj.getEndDate(), "yyyy-MM-dd HH:mm:ss", "yyyyMMdd");
        } else {
            beginDate = DateUtil.tranceDateFormat(obj.getBeginDate(), "yyyy-MM-dd HH:mm:ss", "yyyyMMddHHmmss");
            endDate = DateUtil.tranceDateFormat(obj.getEndDate(), "yyyy-MM-dd HH:mm:ss", "yyyyMMddHHmmss");
        }

        return service.steelRep(beginDate, endDate);
    }

    @ResponseBody
    @Operation(summary = "酸轧客户钢种宽度厚度分析报表", description = "酸轧客户钢种宽度厚度分析报表")
    @PostMapping("/clientSteelRep")
    public ResultData<ClientSteelGradeThickWidthRes> clientSteelRep(@RequestBody BaseRangeObj obj) {
        String beginDate = obj.getBeginDate();
        String endDate = obj.getEndDate();
        if (StringUtils.isEmpty(beginDate)) {
            //不传开始时间，查询昨日数据
            beginDate = DateUtil.getDateToString(DateUtil.getLastDayZero(new Date()), "yyyyMMdd");
            endDate = DateUtil.getDateToString(DateUtil.getCurrentZero(new Date()), "yyyyMMdd");
        } else if ((beginDate.endsWith("00:00:00") && endDate.endsWith("00:00:00"))) {
            //区分整日查询和精确查询
            beginDate = DateUtil.tranceDateFormat(obj.getBeginDate(), "yyyy-MM-dd HH:mm:ss", "yyyyMMdd");
            endDate = DateUtil.tranceDateFormat(obj.getEndDate(), "yyyy-MM-dd HH:mm:ss", "yyyyMMdd");
        } else {
            beginDate = DateUtil.tranceDateFormat(obj.getBeginDate(), "yyyy-MM-dd HH:mm:ss", "yyyyMMddHHmmss");
            endDate = DateUtil.tranceDateFormat(obj.getEndDate(), "yyyy-MM-dd HH:mm:ss", "yyyyMMddHHmmss");
        }
        return service.clientSteelRep(beginDate, endDate);
    }
}
